(function() {
  var AccountView, FeedbackCollectionView, FriendshipRequestCollectionView, LoginForm, MainRouter, MessageCollectionView, MessageFormView, Profile, ProfileFeedbackSection, ProfileSkillSection, ProposalsView, RegistrationForm, SearchView, SkillCollectionView, UserCollectionView,
    __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  RegistrationForm = (function(_super) {

    __extends(RegistrationForm, _super);

    function RegistrationForm() {
      this.validate = __bind(this.validate, this);
      return RegistrationForm.__super__.constructor.apply(this, arguments);
    }

    RegistrationForm.prototype.emailIsValid = false;

    RegistrationForm.prototype.passwordIsValid = false;

    RegistrationForm.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.emailBox = this.el.find("input[name='email']");
      this.passwordBox = this.el.find("input[name='password']");
      this.confirmationBox = this.el.find("input[name='cpassword']");
      this.delegate();
      return this.render();
    };

    RegistrationForm.prototype.delegate = function() {
      var context, registerFunction;
      context = this;
      registerFunction = function(e) {
        e.preventDefault();
        return context.registerUser();
      };
      this.emailBox.keyup(this.validate);
      this.passwordBox.keyup(this.validate);
      this.confirmationBox.keyup(this.validate);
      return this.el.submit(registerFunction);
    };

    RegistrationForm.prototype.render = function() {
      var rightColor, wrongColor;
      wrongColor = "rgb(255, 172, 98)";
      rightColor = "rgb(85, 255, 174)";
      if (this.emailBox.hasValue()) {
        if (this.emailIsValid) {
          this.emailBox.highlight(rightColor);
        } else {
          this.emailBox.highlight(wrongColor);
        }
      }
      if (this.passwordBox.hasValue()) {
        if (this.passwordIsValid) {
          this.passwordBox.highlight(rightColor);
          return this.confirmationBox.highlight(rightColor);
        } else {
          this.passwordBox.highlight(wrongColor);
          return this.confirmationBox.highlight(wrongColor);
        }
      }
    };

    RegistrationForm.prototype.email = function() {
      return this.emailBox.val();
    };

    RegistrationForm.prototype.password = function() {
      return this.passwordBox.val();
    };

    RegistrationForm.prototype.cpassword = function() {
      return this.confirmationBox.val();
    };

    RegistrationForm.prototype.validate = function() {
      this.emailIsValid = checkEmail(this.email());
      this.passwordIsValid = checkPassword(this.password(), this.cpassword());
      this.render();
      return this.emailIsValid && this.passwordIsValid;
    };

    RegistrationForm.prototype.registerUser = function() {
      var email, error, password, success, user,
        _this = this;
      if (!this.validate()) {
        alert("Email and/or password are not valid!");
        return;
      }
      email = this.email();
      password = this.password();
      success = function() {
        return alert("You have been registered. Check your inbox email to activate your account.");
      };
      error = newErrorCallback("Registration failed because of an error.", function() {
        return _this.el.fadeIn();
      });
      user = new window.model.User();
      user.register(email, password, success, error);
      return this.el.fadeOut();
    };

    return RegistrationForm;

  })(Backbone.View);

  LoginForm = (function(_super) {

    __extends(LoginForm, _super);

    function LoginForm() {
      return LoginForm.__super__.constructor.apply(this, arguments);
    }

    LoginForm.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.emailBox = this.el.find("input[name='email']");
      this.passwordBox = this.el.find("input[name='password']");
      this.delegate();
      return this.render();
    };

    LoginForm.prototype.delegate = function() {
      var context, loginFunction;
      context = this;
      loginFunction = function(e) {
        e.preventDefault();
        return context.loginUser();
      };
      return this.el.submit(loginFunction);
    };

    LoginForm.prototype.email = function() {
      return this.emailBox.val();
    };

    LoginForm.prototype.password = function() {
      return this.passwordBox.val();
    };

    LoginForm.prototype.validate = function() {
      return this.emailBox.hasValue() && this.passwordBox.hasValue();
    };

    LoginForm.prototype.loginUser = function() {
      var email, error, password, success,
        _this = this;
      if (!this.validate()) {
        alert("You need email and password to login!");
        return;
      }
      this.el.fadeOut();
      success = function(sessionHash) {
        _this.showLoggedGui();
        $.cookie(window.COOKIE_NAME, sessionHash);
        window.loadPersonalInfo();
        window.showPanel(window.profilePanel);
        return window.profile.showSection("information");
      };
      error = window.newErrorCallback("Cannot login!", function() {
        return _this.el.fadeIn();
      });
      email = this.email();
      password = this.password();
      return utils.User.login(email, password, success, error);
    };

    LoginForm.prototype.showLoggedGui = function() {
      return $(".notLoggedIn").fadeReplace($(".loggedIn"));
    };

    LoginForm.prototype.hideLoggedGui = function() {
      $(".loggedIn").fadeReplace($(".notLoggedIn, .notLoggedIn *"));
      return window.panels.visibles().fadeReplace(window.homePanel);
    };

    return LoginForm;

  })(Backbone.View);

  Profile = (function(_super) {

    __extends(Profile, _super);

    function Profile() {
      this.addFriend = __bind(this.addFriend, this);

      this.removeFriend = __bind(this.removeFriend, this);

      this.promoteUser = __bind(this.promoteUser, this);

      this.demoteUser = __bind(this.demoteUser, this);

      this.forcePasswordChange = __bind(this.forcePasswordChange, this);

      this.deleteUser = __bind(this.deleteUser, this);

      this.deleteAvatar = __bind(this.deleteAvatar, this);

      this.uploadAvatar = __bind(this.uploadAvatar, this);

      this.saveProfile = __bind(this.saveProfile, this);

      this.enableEditMode = __bind(this.enableEditMode, this);

      this.emailChanged = __bind(this.emailChanged, this);

      this.informationChanged = __bind(this.informationChanged, this);

      this.descriptionChanged = __bind(this.descriptionChanged, this);

      this.nameChanged = __bind(this.nameChanged, this);

      this.idChanged = __bind(this.idChanged, this);
      return Profile.__super__.constructor.apply(this, arguments);
    }

    Profile.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.model = window.targetUser;
      this.usernameArea = this.el.find("#userHeader header");
      this.descriptionArea = this.el.find("#userHeader cite");
      this.informationArea = this.el.find("#information");
      this.emailArea = this.el.find("#userHeader .email");
      this.avatarImage = this.el.find("#userHeader .avatar");
      this.skillSection = new ProfileSkillSection({
        el: this.el.find("#skills")
      });
      this.feedbackSection = new ProfileFeedbackSection({
        el: this.el.find("#feedbacks")
      });
      this.infoLink = this.el.find("#infoLink");
      this.skillLink = this.el.find("#skillLink");
      this.feedbackLink = this.el.find("#feedbackLink");
      this.sendMessageLink = this.el.find("#sendMessageLink");
      this.sendMessageForm = new MessageFormView({
        el: this.el.find("#sendMessage form")
      });
      this.editButton = this.el.find("#editProfile");
      this.saveButton = this.el.find("#saveProfile");
      this.promoteButton = this.el.find("#promote");
      this.demoteButton = this.el.find("#demote");
      this.friendsButton = this.el.find("#showFriends");
      this.addFriendButton = this.el.find("#addFriend");
      this.removeFriendButton = this.el.find("#removeFriend");
      this.killButton = this.el.find("#kill");
      this.forcePasswordButton = this.el.find("#forcePassword");
      this.fileArea = this.el.find("input[type='file']");
      this.uploadButton = this.el.find("#uploadAvatar");
      this.deleteAvatarButton = this.el.find("#deleteAvatar");
      this.uploadForm = this.el.find("#uploadForm");
      this.delegate();
      return this.render();
    };

    Profile.prototype.delegate = function() {
      currentUser.on("change:id", this.idChanged);
      this.model.on("change:id", this.idChanged);
      this.model.on("change:name", this.nameChanged);
      this.model.on("change:description", this.descriptionChanged);
      this.model.on("change:information", this.informationChanged);
      this.model.on("change:email", this.emailChanged);
      this.editButton.click(this.enableEditMode);
      this.saveButton.click(this.saveProfile);
      this.uploadButton.click(this.uploadAvatar);
      this.deleteAvatarButton.click(this.deleteAvatar);
      this.killButton.click(this.deleteUser);
      this.forcePasswordButton.click(this.forcePasswordChange);
      this.demoteButton.click(this.demoteUser);
      this.promoteButton.click(this.promoteUser);
      this.removeFriendButton.click(this.removeFriend);
      return this.addFriendButton.click(this.addFriend);
    };

    Profile.prototype.updateLinks = function() {
      var prefix;
      prefix = "#/users/" + this.model.get("id");
      this.infoLink.attr("href", prefix + "/information");
      this.skillLink.attr("href", prefix + "/skills");
      this.feedbackLink.attr("href", prefix + "/feedbacks");
      this.friendsButton.attr("href", prefix + "/friends");
      return this.sendMessageLink.attr("href", prefix + "/sendMessage");
    };

    Profile.prototype.idChanged = function() {
      if (currentUser.isVisitor()) {
        this.promoteButton.hide();
        this.demoteButton.hide();
        this.editButton.hide();
        this.addFriendButton.hide();
        this.removeFriendButton.hide();
        this.forcePasswordButton.hide();
        this.sendMessageLink.hide();
      } else {
        this.sendMessageLink.show();
        if (currentUser.isAdmin()) {
          if (targetUser.isAdmin()) {
            this.promoteButton.hide();
          } else {
            this.promoteButton.show();
          }
        } else {
          this.promoteButton.hide();
        }
        if (currentUser.isSuperUser()) {
          this.editButton.show();
          this.killButton.show();
          this.deleteAvatarButton.show();
          this.forcePasswordButton.show();
          if (targetUser.isAdmin()) {
            this.demoteButton.show();
          } else {
            this.demoteButton.hide();
          }
        } else {
          this.killButton.hide();
          this.deleteAvatarButton.hide();
          this.forcePasswordButton.hide();
        }
        if (isSelfProfile()) {
          this.editButton.show();
          this.promoteButton.hide();
          this.demoteButton.hide();
          this.addFriendButton.hide();
          this.removeFriendButton.hide();
          this.killButton.hide();
          this.forcePasswordButton.show();
        } else {
          if (!currentUser.isSuperUser()) {
            this.editButton.hide();
          }
          this.analyzeFriends();
        }
      }
      this.updateLinks();
      this.skillSection.refresh();
      this.sendMessageForm.recipient = targetUser;
      return this.avatarImage.attr("src", "" + (this.model.url()) + "/avatar");
    };

    Profile.prototype.analyzeFriends = function() {
      var success,
        _this = this;
      success = function() {
        if (isSelfProfile()) {
          _this.addFriendButton.hide();
          _this.removeFriendButton.hide();
          return;
        }
        if (targetUser.friends.where({
          id: currentUser.get("id")
        }).length === 0) {
          _this.addFriendButton.show();
          return _this.removeFriendButton.hide();
        } else {
          _this.addFriendButton.show();
          return _this.removeFriendButton.hide();
        }
      };
      return targetUser.friends.fetch({
        success: success
      });
    };

    Profile.prototype.nameChanged = function() {
      return this.usernameArea.find(".normal").html(this.model.get("name"));
    };

    Profile.prototype.descriptionChanged = function() {
      return this.descriptionArea.find(".normal").html(this.model.get("description"));
    };

    Profile.prototype.informationChanged = function() {
      return this.informationArea.find(".normal").html(this.model.get("information"));
    };

    Profile.prototype.emailChanged = function() {
      return this.emailArea.find(".normal").html(this.model.get("email"));
    };

    Profile.prototype.showSection = function(name) {
      this.el.find("#content section").hide();
      return this.el.find("#" + name).show();
    };

    Profile.prototype.enableEditMode = function() {
      this.editButton.fadeReplace(this.saveButton);
      this.usernameArea.find(".edit input").val(this.usernameArea.find(".normal").text());
      this.descriptionArea.find(".edit input").val(this.descriptionArea.find(".normal").text());
      this.informationArea.find(".edit textarea").val(this.informationArea.find(".normal").text());
      this.emailArea.find(".edit input").val(this.emailArea.find(".normal").text());
      this.el.find(".normal").fadeReplace(this.el.find(".edit"));
      return this.showSection("information");
    };

    Profile.prototype.validate = function() {
      return this.usernameArea.find(".edit input").hasValue() && this.descriptionArea.find(".edit input").hasValue() && this.informationArea.find(".edit textarea").hasValue() && this.emailArea.find(".edit input").hasValue();
    };

    Profile.prototype.saveProfile = function() {
      var attributes, error, newDescription, newEmail, newInformation, newUsername, options, success,
        _this = this;
      if (!this.validate()) {
        alert("Fill the fields with appropriate values!");
        return;
      }
      newUsername = this.usernameArea.find(".edit input").val();
      newDescription = this.descriptionArea.find(".edit input").val();
      newInformation = this.informationArea.find(".edit textarea").val();
      newEmail = this.emailArea.find(".edit input").val();
      attributes = {
        name: newUsername,
        description: newDescription,
        information: newInformation,
        email: newEmail
      };
      success = function() {
        if (isSelfProfile()) {
          _this.model.copyFrom(currentUser);
        }
        return _this.editButton.fadeIn();
      };
      error = newErrorCallback("There was an error editing the profile!", function() {
        return _this.editButton.fadeIn();
      });
      options = {
        success: success,
        error: error
      };
      if (currentUser.isSuperUser()) {
        targetUser.save(attributes, options);
      } else {
        currentUser.save(attributes, options);
      }
      this.saveButton.fadeOut();
      return this.el.find(".edit").fadeReplace(this.el.find(".normal"));
    };

    Profile.prototype.uploadAvatar = function() {
      var context, data, error, progress, success,
        _this = this;
      if (this.fileArea.isEmpty()) {
        alert("Select a file before proceeding!");
        return;
      }
      this.uploadButton.attr("disabled", "disabled");
      data = new FormData(this.uploadForm[0]);
      context = this;
      success = function() {
        var avatar;
        avatar = $("#userHeader .avatar");
        avatar.attr("src", avatar.attr("src"));
        context.uploadButton.attr("value", "Upload");
        return context.uploadButton.removeAttr("disabled");
      };
      error = newErrorCallback("An error occurred while uploading!", function() {
        _this.uploadButton.removeAttr("disabled");
        return _this.uploadButton.attr("value", "Upload");
      });
      progress = function(e) {
        var percent;
        percent = Number(100 * e.loaded / e.total).toFixed(2);
        context.uploadButton.attr("value", "" + percent + "%");
        if (percent === 100.00) {
          return success();
        }
      };
      return currentUser.uploadAvatar(data, success, error, progress);
    };

    Profile.prototype.deleteAvatar = function() {
      var error, success;
      success = function() {
        var avatar;
        avatar = $("#userHeader .avatar");
        return avatar.attr("src", avatar.attr("src"));
      };
      error = newErrorCallback("Cannot delete this avatar!");
      return targetUser.deleteAvatar(success, error);
    };

    Profile.prototype.deleteUser = function() {
      var error, success;
      if (currentUser.isSuperUser()) {
        if (!confirm("Are you sure you want to permantely erase all data about this user? This action cannot be undone.")) {
          return;
        }
        success = function() {
          showPanel(homePanel);
          return alert("The user has been terminated.");
        };
        error = newErrorCallback("Cannot delete this user!");
        return targetUser.destroy({
          success: success,
          error: error
        });
      } else {
        return alert("You are not allowed to delete users.");
      }
    };

    Profile.prototype.forcePasswordChange = function() {
      var cpass, error, pass, success;
      if (currentUser.isSuperUser() || isSelfProfile()) {
        pass = prompt("Insert new password:");
        cpass = prompt("Confirm password:");
        if (pass !== cpass) {
          alert("The two passwords don't match!");
          return;
        }
        success = function() {
          return alert("User password changed successfully!");
        };
        error = newErrorCallback("Cannot change user password!");
        if (isSelfProfile()) {
          return currentUser.forcePassword(pass, success, error);
        } else {
          return targetUser.forcePassword(pass, success, error);
        }
      } else {
        return alert("You are not allowed to perform this action!");
      }
    };

    Profile.prototype.demoteUser = function() {
      var error, success;
      if (currentUser.isSuperUser()) {
        success = function() {
          profile.demoteButton.hide();
          return alert("This administrator has been demoted!");
        };
        error = newErrorCallback("Cannot demote this user!");
        return targetUser.demote(success, error);
      } else {
        return alert("You are not allowed to demote.");
      }
    };

    Profile.prototype.promoteUser = function() {
      var error, success;
      if (currentUser.isAdmin()) {
        success = function() {
          this.promoteButton.hide();
          this.demoteButton.show();
          return alert("The user has been promoted!");
        };
        error = newErrorCallback("Cannot promote this user!");
        return targetUser.promote(success, error);
      } else {
        return alert("You are not allowed to promote.");
      }
    };

    Profile.prototype.removeFriend = function() {
      var error, success,
        _this = this;
      success = function() {
        alert(targetUser.get("name") + " is no longer your friend!");
        _this.removeFriendButton.hide();
        return _this.addFriendButton.show();
      };
      error = newErrorCallback("Cannot cancel friendship!");
      return currentUser.removeFriend(targetUser, success, error);
    };

    Profile.prototype.addFriend = function() {
      var error, request, success;
      success = function() {
        return alert("You have sent a friendship request!");
      };
      error = newErrorCallback("Cannot request friendship to that user!");
      request = new model.FriendshipRequest();
      request.set("target", targetUser);
      return request.send(success, error);
    };

    return Profile;

  })(Backbone.View);

  SkillCollectionView = (function(_super) {

    __extends(SkillCollectionView, _super);

    function SkillCollectionView() {
      this.skillRemoved = __bind(this.skillRemoved, this);

      this.skillReset = __bind(this.skillReset, this);

      this.skillAdded = __bind(this.skillAdded, this);
      return SkillCollectionView.__super__.constructor.apply(this, arguments);
    }

    SkillCollectionView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.comboMode = this.el.is("select");
      this.compactMode = this.el.hasClass("compact");
      if (!this.model) {
        this.model = new collection.Skill();
      }
      this.render();
      return this.delegate();
    };

    SkillCollectionView.prototype.delegate = function() {
      this.model.on("add", this.skillAdded);
      this.model.on("reset", this.skillReset);
      return this.model.on("remove", this.skillRemoved);
    };

    SkillCollectionView.prototype.createSkillItem = function(skill) {
      var code, description, id, name;
      name = skill.get("name");
      description = skill.get("description");
      id = skill.get("id");
      code = "            <li class='skill' id='s" + id + "'>                <h3 class='name'>" + name + "</h3>                <span class='description'>" + description + "</span>            </li>";
      return $(code);
    };

    SkillCollectionView.prototype.createCompactSkillItem = function(skill) {
      var id, name;
      name = skill.get("name");
      id = skill.get("id");
      return $("<li id='s" + id + "'><input type='checkbox' /> " + name + "</li>");
    };

    SkillCollectionView.prototype.createSkillOption = function(skill) {
      var id, name;
      name = skill.get("name");
      id = skill.get("id");
      return $("<option value='" + id + "'>" + name + "</option>");
    };

    SkillCollectionView.prototype.skillAdded = function(skill) {
      var item;
      if (this.comboMode) {
        item = this.createSkillOption(skill);
      } else {
        if (this.compactMode) {
          item = this.createCompactSkillItem(skill);
        } else {
          item = this.createSkillItem(skill);
        }
      }
      if (this.onItemCreated) {
        this.onItemCreated(item, skill);
      }
      return this.el.append(item);
    };

    SkillCollectionView.prototype.skillReset = function() {
      var i, _i, _ref, _results;
      this.el.empty();
      if (this.model && this.model.length > 0) {
        _results = [];
        for (i = _i = 0, _ref = this.model.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
          _results.push(this.skillAdded(this.model.at(i)));
        }
        return _results;
      }
    };

    SkillCollectionView.prototype.render = function() {
      return this.skillReset();
    };

    SkillCollectionView.prototype.skillRemoved = function(skill) {
      return this.skillReset();
    };

    return SkillCollectionView;

  })(Backbone.View);

  ProfileSkillSection = (function(_super) {

    __extends(ProfileSkillSection, _super);

    function ProfileSkillSection() {
      this.removeSkill = __bind(this.removeSkill, this);

      this.proposeSkill = __bind(this.proposeSkill, this);

      this.deleteSkill = __bind(this.deleteSkill, this);

      this.addSkill = __bind(this.addSkill, this);

      this.populateCombo = __bind(this.populateCombo, this);

      this.hookListItem = __bind(this.hookListItem, this);
      return ProfileSkillSection.__super__.constructor.apply(this, arguments);
    }

    ProfileSkillSection.prototype.initialize = function() {
      var list;
      this.el = jQuery(this.el);
      list = this.el.find("ul");
      this.skillList = new SkillCollectionView({
        el: list,
        model: targetUser.skills
      });
      if (skillDatabase.isEmpty()) {
        skillDatabase.fetch({
          success: this.populateCombo
        });
      } else {
        this.populateCombo();
      }
      this.addForm = this.el.find("#addSkill");
      this.addButton = this.el.find("#addSkill #addSkillButton");
      this.deleteButton = this.el.find("#addSkill #delSkillButton");
      this.proposeButton = this.el.find("#proposeSkill input[type='button']");
      this.proposeForm = this.el.find("#proposeSkill");
      this.proposalNameBox = this.el.find("#proposeSkill input[name='proposal']");
      this.proposalDescriptionBox = this.el.find("#proposeSkill input[name='proposalDescription']");
      return this.delegate();
    };

    ProfileSkillSection.prototype.delegate = function() {
      this.addButton.click(this.addSkill);
      this.deleteButton.click(this.deleteSkill);
      this.proposeButton.click(this.proposeSkill);
      return this.skillList.onItemCreated = this.hookListItem;
    };

    ProfileSkillSection.prototype.hookListItem = function(item, skill) {
      var context, removeLink, sid, title;
      if (!isSelfProfile()) {
        return;
      }
      sid = skill.get("id");
      removeLink = $("<span> (<a href='remove" + sid + "'>X</a>) </span>");
      title = item.find("h3");
      title.append(removeLink);
      context = this;
      return removeLink.find("a").click(function(e) {
        e.preventDefault();
        return context.removeSkill(sid);
      });
    };

    ProfileSkillSection.prototype.populateCombo = function() {
      var combo;
      combo = this.el.find("select");
      return this.skillCombo = new SkillCollectionView({
        el: combo,
        model: skillDatabase
      });
    };

    ProfileSkillSection.prototype.refresh = function() {
      if (currentUser.isVisitor()) {
        this.addForm.hide();
        this.proposeForm.hide();
        this.deleteButton.hide();
      } else {
        this.proposeForm.show();
        if (isSelfProfile()) {
          this.addForm.show();
        } else {
          this.addForm.hide();
        }
        if (currentUser.isAdmin()) {
          this.proposeForm.find("h3").html("Declare a skill!");
        } else {
          this.proposeForm.find("h3").html("Propose a skill!");
        }
        if (currentUser.isSuperUser()) {
          this.deleteButton.show();
        } else {
          this.deleteButton.hide();
        }
      }
      this.skillList.model.url = function() {
        return targetUser.url() + "/skills";
      };
      this.skillList.model.reset();
      return this.skillList.model.fetch();
    };

    ProfileSkillSection.prototype.addSkill = function() {
      var error, sid, skill, success,
        _this = this;
      if (skillDatabase.isEmpty()) {
        skillDatabase.fetch({
          success: this.addSkill
        });
        return;
      }
      sid = Number(this.skillCombo.el.val());
      skill = skillDatabase.getById(sid);
      if (!skill) {
        alert("No such skill!");
        return;
      }
      success = function() {
        return _this.skillList.model.add(skill);
      };
      error = newErrorCallback("Cannot add that skill!");
      return currentUser.addSkill(skill, success, error);
    };

    ProfileSkillSection.prototype.deleteSkill = function() {
      var error, sid, skill, success, thatSkill,
        _this = this;
      sid = Number(this.skillCombo.el.val());
      skill = skillDatabase.getById(sid);
      if (!skill) {
        alert("That skill does not exist!");
        return;
      }
      success = function() {
        _this.skillList.model.remove(skill);
        return _this.skillList.render();
      };
      error = newErrorCallback("Cannot delete that skill!");
      thatSkill = new model.Skill();
      thatSkill.set("id", sid);
      thatSkill.url = function() {
        return "" + ROOT_URL + "/skills";
      };
      return thatSkill.destroy({
        success: success,
        error: error
      });
    };

    ProfileSkillSection.prototype.proposeSkill = function() {
      var error, skill, success;
      if (this.proposalNameBox.isEmpty() || this.proposalDescriptionBox.isEmpty()) {
        alert("Fill the fields correctly!");
        return;
      }
      skill = new model.Skill();
      skill.set("name", this.proposalNameBox.val());
      skill.set("description", this.proposalDescriptionBox.val());
      if (currentUser.isAdmin()) {
        success = function() {
          return alert("Skill created! Reload the page to see it in the list.");
        };
      } else {
        success = function() {
          return alert("Your proposal has been posted and will be reviewed asap!");
        };
      }
      error = newErrorCallback("Cannot send proposal!");
      return skill.propose(success, error);
    };

    ProfileSkillSection.prototype.removeSkill = function(id) {
      var error, skill, success, thatSkill,
        _this = this;
      skill = skillDatabase.getById(id);
      if (!skill) {
        alert("No such skill to remove!");
        return;
      }
      success = function() {
        return _this.skillList.model.remove(skill);
      };
      error = newErrorCallback("Cannot remove that skill!");
      thatSkill = new model.Skill();
      thatSkill.set("id", id);
      thatSkill.url = function() {
        return currentUser.url() + ("/skills/" + id);
      };
      return thatSkill.destroy({
        success: success,
        error: error
      });
    };

    return ProfileSkillSection;

  })(Backbone.View);

  FeedbackCollectionView = (function(_super) {

    __extends(FeedbackCollectionView, _super);

    function FeedbackCollectionView() {
      this.feedbackReset = __bind(this.feedbackReset, this);

      this.feedbackAdded = __bind(this.feedbackAdded, this);
      return FeedbackCollectionView.__super__.constructor.apply(this, arguments);
    }

    FeedbackCollectionView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      if (!this.model) {
        this.model = new collection.Feedback();
      }
      return this.delegate();
    };

    FeedbackCollectionView.prototype.delegate = function() {
      this.model.on("add", this.feedbackAdded);
      return this.model.on("reset", this.feedbackReset);
    };

    FeedbackCollectionView.prototype.feedbackAdded = function(feedback) {
      var author, code, id, item, rating, text;
      rating = feedback.get("rating");
      author = feedback.get("author").name;
      id = feedback.get("author").id;
      text = feedback.get("text");
      if (feedback.get("author").get) {
        author = feedback.get("author").get("name");
      }
      if (feedback.get("author").get) {
        id = feedback.get("author").get("id");
      }
      if (rating.toString().length > 1) {
        if (rating.indexOf("One") === 0) {
          rating = 1;
        } else if (rating.indexOf("Two") === 0) {
          rating = 2;
        } else if (rating.indexOf("Three") === 0) {
          rating = 3;
        } else if (rating.indexOf("Four") === 0) {
          rating = 4;
        } else {
          rating = 5;
        }
      }
      code = "            <li class='feedback'>                <img class='avatar' src='" + ROOT_URL + "/users/" + id + "/avatar'/>                <h3 class='title'>" + author + " said: " + rating + " stars</h3>                <p class='comment'>" + text + "</p>            </li>";
      item = $(code);
      return this.el.append(item);
    };

    FeedbackCollectionView.prototype.feedbackReset = function() {
      var i, _i, _ref, _results;
      this.el.empty();
      if (this.model.length > 0) {
        _results = [];
        for (i = _i = 0, _ref = this.model.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
          _results.push(this.feedbackAdded(this.model.at(i)));
        }
        return _results;
      }
    };

    return FeedbackCollectionView;

  })(Backbone.View);

  ProfileFeedbackSection = (function(_super) {

    __extends(ProfileFeedbackSection, _super);

    function ProfileFeedbackSection() {
      this.sendFeedback = __bind(this.sendFeedback, this);

      this.showFeedbacks = __bind(this.showFeedbacks, this);
      return ProfileFeedbackSection.__super__.constructor.apply(this, arguments);
    }

    ProfileFeedbackSection.prototype.initialize = function() {
      var combo, list;
      this.el = jQuery(this.el);
      this.form = this.el.find("#sendFeedbackForm");
      this.ratingCombo = this.form.find("select[name='rating']");
      this.commentArea = this.form.find("textarea[name='comment']");
      list = this.el.find("ul");
      combo = this.el.find("select");
      this.skillCombo = new SkillCollectionView({
        el: combo,
        model: targetUser.skills
      });
      this.feedbackList = new FeedbackCollectionView({
        el: list
      });
      this.showButton = this.el.find("#selectSkill input");
      return this.delegate();
    };

    ProfileFeedbackSection.prototype.delegate = function() {
      var callback;
      this.showButton.click(this.showFeedbacks);
      callback = this.sendFeedback;
      return this.form.submit(function(e) {
        e.preventDefault();
        return callback();
      });
    };

    ProfileFeedbackSection.prototype.showFeedbacks = function() {
      var sid;
      sid = this.skillCombo.el.val();
      this.feedbackList.model.url = function() {
        return targetUser.url() + ("/skills/" + sid + "/feedbacks");
      };
      return this.feedbackList.model.fetch();
    };

    ProfileFeedbackSection.prototype.refresh = function() {
      if (currentUser.isVisitor()) {
        this.form.hide();
      } else {
        this.form.show();
      }
      this.skillCombo.model.reset();
      return this.skillCombo.model.fetch();
    };

    ProfileFeedbackSection.prototype.sendFeedback = function() {
      var attributes, author, comment, error, feedback, options, rating, sid, success,
        _this = this;
      if (this.ratingCombo.isEmpty() || this.commentArea.isEmpty()) {
        alert("Fill the required fields!");
        return;
      }
      sid = this.skillCombo.el.val();
      rating = this.ratingCombo.val();
      comment = this.commentArea.val();
      author = currentUser;
      feedback = new model.Feedback();
      feedback.url = function() {
        return targetUser.url() + ("/skills/" + sid + "/feedbacks");
      };
      attributes = {
        rating: rating,
        text: comment
      };
      success = function() {
        feedback.set("author", author);
        return _this.feedbackList.model.add(feedback);
      };
      error = newErrorCallback("Cannot send feedback!");
      options = {
        success: success,
        error: error
      };
      return feedback.save(attributes, options);
    };

    return ProfileFeedbackSection;

  })(Backbone.View);

  MessageFormView = (function(_super) {

    __extends(MessageFormView, _super);

    function MessageFormView() {
      return MessageFormView.__super__.constructor.apply(this, arguments);
    }

    MessageFormView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.textArea = this.el.find("textarea");
      return this.delegate();
    };

    MessageFormView.prototype.delegate = function() {
      var callback, context;
      context = this;
      callback = function(e) {
        e.preventDefault();
        return context.sendMessage();
      };
      return this.el.submit(callback);
    };

    MessageFormView.prototype.sendMessage = function() {
      var error, externalCallback, message, success,
        _this = this;
      if (this.textArea.isEmpty()) {
        alert("Insert a message before sending!");
        return;
      }
      if (!this.recipient && !this.recipientId) {
        return;
      }
      if (this.onMessageSent) {
        externalCallback = this.onMessageSent;
        success = function() {
          externalCallback();
          return alert("Message sent!");
        };
      } else {
        success = function() {
          return alert("Message sent!");
        };
      }
      error = newErrorCallback("Cannot send message!");
      message = new model.Message();
      message.set("text", this.textArea.val());
      if (this.recipient) {
        return message.sendTo(this.recipient, success, error);
      } else {
        return message.sendToId(this.recipientId, success, error);
      }
    };

    return MessageFormView;

  })(Backbone.View);

  MessageCollectionView = (function(_super) {

    __extends(MessageCollectionView, _super);

    function MessageCollectionView() {
      this.messageReset = __bind(this.messageReset, this);

      this.messageAdded = __bind(this.messageAdded, this);

      this.createMessageItem = __bind(this.createMessageItem, this);
      return MessageCollectionView.__super__.constructor.apply(this, arguments);
    }

    MessageCollectionView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      return this.delegate();
    };

    MessageCollectionView.prototype.delegate = function() {
      this.model.on("add", this.messageAdded);
      return this.model.on("reset", this.messageReset);
    };

    MessageCollectionView.prototype.createMessageItem = function(message) {
      var code, date, id, sender, text;
      sender = message.get("sender").name;
      id = message.get("sender").id;
      text = message.get("text");
      date = new Date(Number(message.get("date")));
      if (message.get("sender").get) {
        sender = message.get("sender").get("name");
        id = message.get("sender").get("id");
      }
      code = "            <li class='message'>                <img class='avatar' src='" + ROOT_URL + "/users/" + id + "/avatar' />                <h3 class='sender'>" + sender + " <a href='#/replyto/" + id + "'> <img src='icons/reply.png' class='reply' /> </a> </h3>                <p class='text'>" + text + "</p>                <p class='date'>sent on " + (formatDate(date, true)) + "</p>            </li>";
      return $(code);
    };

    MessageCollectionView.prototype.createFormView = function(recipientId) {
      var code, form, view,
        _this = this;
      code = "            <form name='replyForm' id='replyForm'>                <textarea rows='6' cols='100' name='text'>Message</textarea>                <input type='submit' value='Send' class='right' />            </form>";
      form = $(code);
      view = new MessageFormView({
        el: form
      });
      view.recipientId = recipientId;
      view.onMessageSent = function() {
        return form.remove();
      };
      return view;
    };

    MessageCollectionView.prototype.messageAdded = function(message) {
      var context, id, item, replyLink, sender,
        _this = this;
      context = this;
      item = this.createMessageItem(message);
      replyLink = item.find("a");
      sender = message.get("sender");
      if (sender.get) {
        id = sender.get("id");
      } else {
        id = sender.id;
      }
      replyLink.click(function(e) {
        var formView;
        if (item.find("form").size() === 0) {
          formView = context.createFormView(id);
          return item.append(formView.el);
        }
      });
      return this.el.append(item);
    };

    MessageCollectionView.prototype.messageReset = function() {
      var i, _i, _ref, _results;
      this.el.empty();
      if (this.model.length > 0) {
        _results = [];
        for (i = _i = 0, _ref = this.model.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
          _results.push(this.messageAdded(this.model.at(i)));
        }
        return _results;
      }
    };

    return MessageCollectionView;

  })(Backbone.View);

  FriendshipRequestCollectionView = (function(_super) {

    __extends(FriendshipRequestCollectionView, _super);

    function FriendshipRequestCollectionView() {
      this.requestReset = __bind(this.requestReset, this);

      this.requestAdded = __bind(this.requestAdded, this);

      this.createRequestItem = __bind(this.createRequestItem, this);
      return FriendshipRequestCollectionView.__super__.constructor.apply(this, arguments);
    }

    FriendshipRequestCollectionView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      return this.delegate();
    };

    FriendshipRequestCollectionView.prototype.delegate = function() {
      this.model.on("add", this.requestAdded);
      return this.model.on("reset", this.requestReset);
    };

    FriendshipRequestCollectionView.prototype.createRequestItem = function(request) {
      var code, date, id, sender;
      sender = request.getSenderName();
      id = request.getId();
      date = new Date(Number(request.get("date")));
      code = "            <li class='request'>                <img class='avatar' src='" + ROOT_URL + "/users/" + id + "/avatar' />                <h3 class='sender'>" + sender + "</h3> <span class='date'>" + (formatDate(date)) + "</span> <br/>                <a href='#/accept/" + id + "'>Accept</a> &nbsp; - &nbsp; <a href='#/decline/" + id + "'>Decline</a>            </li>";
      return $(code);
    };

    FriendshipRequestCollectionView.prototype.requestAdded = function(request) {
      var acceptLink, declineLink, error, id, item, sender, successAccepted, successDeclined,
        _this = this;
      item = this.createRequestItem(request);
      id = request.getId();
      sender = request.getSenderName();
      acceptLink = item.find("a[href='#/accept/" + id + "']");
      declineLink = item.find("a[href='#/decline/" + id + "']");
      error = newErrorCallback("Cannot process that request!");
      successAccepted = function() {
        _this.model.remove(request);
        return item.html("<em><strong>" + sender + "</strong> has been accepted</em>");
      };
      successDeclined = function() {
        _this.model.remove(request);
        return item.html("<em><strong>" + sender + "</strong> has been rejected</em>");
      };
      acceptLink.click(function(e) {
        e.preventDefault();
        return request.accept(successAccepted, error);
      });
      declineLink.click(function(e) {
        e.preventDefault();
        return request.decline(successDeclined, error);
      });
      return this.el.append(item);
    };

    FriendshipRequestCollectionView.prototype.requestReset = function() {
      var i, _i, _ref, _results;
      this.el.empty();
      if (this.model.length > 0) {
        _results = [];
        for (i = _i = 0, _ref = this.model.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
          _results.push(this.requestAdded(this.model.at(i)));
        }
        return _results;
      }
    };

    return FriendshipRequestCollectionView;

  })(Backbone.View);

  SearchView = (function(_super) {

    __extends(SearchView, _super);

    function SearchView() {
      this.searchByName = __bind(this.searchByName, this);

      this.search = __bind(this.search, this);

      this.quickSearch = __bind(this.quickSearch, this);

      this.redirectSearch = __bind(this.redirectSearch, this);

      this.ready = __bind(this.ready, this);

      this.populateList = __bind(this.populateList, this);
      return SearchView.__super__.constructor.apply(this, arguments);
    }

    SearchView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.searchBox = this.el.find("#skillQuickSearchBox");
      this.friendBox = this.el.find("#searchForm input[name='onlyFriends'], #searchForm label");
      this.form = this.el.find("#searchForm");
      this.barSearch = $("#quickSearch form");
      this.nameSearchBox = this.el.find("#searchByName input[type='text']");
      this.nameSearchButton = this.el.find("#searchByName input[type='button']");
      this.backButton = $("#backToSearch");
      this.ensureSkillsAreThere();
      return this.delegate();
    };

    SearchView.prototype.delegate = function() {
      var _this = this;
      this.searchBox.keyup(this.quickSearch);
      this.form.submit(this.search);
      this.barSearch.submit(this.redirectSearch);
      this.nameSearchButton.click(this.searchByName);
      return this.backButton.click(function() {
        return window.showPanel(searchPanel);
      });
    };

    SearchView.prototype.ensureSkillsAreThere = function() {
      if (skillDatabase.isEmpty()) {
        return skillDatabase.fetch({
          success: this.populateList
        });
      } else {
        return this.populateList();
      }
    };

    SearchView.prototype.populateList = function() {
      this.skillList = new SkillCollectionView({
        el: this.el.find("#skillList ul"),
        model: skillDatabase
      });
      return this.ready();
    };

    SearchView.prototype.show = function() {
      if (window.isLogged()) {
        this.friendBox.show();
      } else {
        this.friendBox.hide();
      }
      return this.ensureSkillsAreThere();
    };

    SearchView.prototype.ready = function() {
      this.skillItems = this.skillList.el.find("li");
      if (this.searchBox.hasValue()) {
        return this.quickSearch();
      }
    };

    SearchView.prototype.redirectSearch = function(e) {
      e.preventDefault();
      this.searchBox.val(this.barSearch.find("input").val());
      window.showPanel(searchPanel);
      return this.show();
    };

    SearchView.prototype.quickSearch = function() {
      var callback, query;
      query = this.searchBox.val().toLowerCase();
      callback = function() {
        var item, itemText;
        item = $(this);
        itemText = item.text().toLowerCase();
        if (itemText.indexOf(query) < 0) {
          return item.hide();
        } else {
          return item.show();
        }
      };
      return this.skillItems.each(callback);
    };

    SearchView.prototype.search = function(e) {
      var onlyFriends, query, rating, skills;
      e.preventDefault();
      rating = this.form.find("select").val();
      if (this.form.find("input[name='onlyFriends']").attr("checked")) {
        onlyFriends = true;
      } else {
        onlyFriends = false;
      }
      skills = "";
      this.skillItems.each(function() {
        if ($(this).find("input").attr("checked")) {
          return skills += "skills=" + $(this).attr("id").substr(1) + "&";
        }
      });
      skills = skills.substr(0, skills.length - 1);
      if (rating > 0) {
        query = "minRating=" + rating + "&";
      } else {
        query = "";
      }
      if (onlyFriends) {
        query += "onlyFriends=1&";
      } else {
        query += "onlyFriends=0&";
      }
      query += skills;
      window.userView.model.url = function() {
        return window.ROOT_URL + "/help?" + query;
      };
      window.userView.model.reset();
      window.userView.model.fetch();
      return window.showPanel(resultPanel);
    };

    SearchView.prototype.searchByName = function(e) {
      var name;
      e.preventDefault();
      if (this.nameSearchBox.isEmpty()) {
        alert("Fill in the search box!");
        return;
      }
      name = this.nameSearchBox.val();
      window.userView.model.url = function() {
        return window.ROOT_URL + ("/users?name=" + name);
      };
      window.userView.model.reset();
      window.userView.model.fetch();
      return window.showPanel(resultPanel);
    };

    return SearchView;

  })(Backbone.View);

  UserCollectionView = (function(_super) {

    __extends(UserCollectionView, _super);

    function UserCollectionView() {
      this.userReset = __bind(this.userReset, this);

      this.userAdded = __bind(this.userAdded, this);
      return UserCollectionView.__super__.constructor.apply(this, arguments);
    }

    UserCollectionView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.model = new window.collection.User();
      return this.delegate();
    };

    UserCollectionView.prototype.delegate = function() {
      this.model.on("add", this.userAdded);
      return this.model.on("reset", this.userReset);
    };

    UserCollectionView.prototype.createUserItem = function(user) {
      var code, description, email, id, name;
      name = user.get("name");
      id = user.get("id");
      description = user.get("description");
      email = user.get("email");
      code = "            <li class='user'>                <img src='" + ROOT_URL + "/users/" + id + "/avatar' class='avatar' />                <a href='#/users/" + id + "'> <h3 class='name'> " + name + " </h3> </a>                <em class='description'>" + description + "</em> <br/>                <em class='email'>" + email + "</em>            </li>";
      return $(code);
    };

    UserCollectionView.prototype.userAdded = function(user) {
      var item;
      item = this.createUserItem(user);
      return this.el.append(item);
    };

    UserCollectionView.prototype.userReset = function() {
      var i, _i, _ref, _results;
      this.el.empty();
      if (this.model.length > 0) {
        _results = [];
        for (i = _i = 0, _ref = this.model.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
          _results.push(this.userAdded(this.model.at(i)));
        }
        return _results;
      }
    };

    return UserCollectionView;

  })(Backbone.View);

  ProposalsView = (function(_super) {

    __extends(ProposalsView, _super);

    function ProposalsView() {
      this.decline = __bind(this.decline, this);

      this.approve = __bind(this.approve, this);

      this.hookListItem = __bind(this.hookListItem, this);
      return ProposalsView.__super__.constructor.apply(this, arguments);
    }

    ProposalsView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.skillList = new SkillCollectionView({
        el: this.el.find("ul")
      });
      this.skillList.model.url = function() {
        return "" + ROOT_URL + "/skills/proposals";
      };
      return this.delegate();
    };

    ProposalsView.prototype.delegate = function() {
      return this.skillList.onItemCreated = this.hookListItem;
    };

    ProposalsView.prototype.hookListItem = function(item, skill) {
      var approveLink, context, declineLink, sid, title;
      sid = skill.get("id");
      title = item.find("h3");
      approveLink = $("<a href='#/approve/" + sid + "' title='Approve'> <img class='small' src='icons/add.png' /> </a>");
      declineLink = $("<a href='#/decline/" + sid + "' title='Reject'> <img class='small' src='icons/delete.png' /> </a> ");
      title.append(approveLink);
      title.append(declineLink);
      context = this;
      approveLink.click(function(e) {
        e.preventDefault();
        return context.approve(skill);
      });
      return declineLink.click(function(e) {
        e.preventDefault();
        return context.decline(skill);
      });
    };

    ProposalsView.prototype.refresh = function() {
      this.skillList.model.reset();
      return this.skillList.model.fetch();
    };

    ProposalsView.prototype.approve = function(skill) {
      var error, success,
        _this = this;
      success = function() {
        _this.skillList.model.remove(skill);
        return alert("The skill has been approved!");
      };
      error = newErrorCallback("Cannot approve this skill!");
      return skill.approve(success, error);
    };

    ProposalsView.prototype.decline = function(skill) {
      var error, success,
        _this = this;
      success = function() {
        _this.skillList.model.remove(skill);
        return alert("That skill has been declined!");
      };
      error = newErrorCallback("Cannot recjet this skill!");
      return skill.decline(success, error);
    };

    return ProposalsView;

  })(Backbone.View);

  AccountView = (function(_super) {

    __extends(AccountView, _super);

    function AccountView() {
      this.accountReset = __bind(this.accountReset, this);

      this.resetPasswordViaUsername = __bind(this.resetPasswordViaUsername, this);

      this.resetPasswordViaEmail = __bind(this.resetPasswordViaEmail, this);

      this.idChanged = __bind(this.idChanged, this);
      return AccountView.__super__.constructor.apply(this, arguments);
    }

    AccountView.prototype.initialize = function() {
      this.el = jQuery(this.el);
      this.emailForm = this.el.find("#resetViaEmailForm");
      this.emailBox = this.emailForm.find("input[type='email']");
      this.usernameForm = this.el.find("#resetViaUsernameForm");
      this.usernameBox = this.usernameForm.find("input[type='text']");
      this.manualActivation = this.el.find("#manualActivation");
      this.inactiveUsers = new collection.User();
      this.inactiveUsers.url = function() {
        return "" + ROOT_URL + "/accounts/inactive";
      };
      this.accountList = this.manualActivation.find("ul");
      return this.delegate();
    };

    AccountView.prototype.delegate = function() {
      this.emailForm.submit(this.resetPasswordViaEmail);
      this.usernameForm.submit(this.resetPasswordViaUsername);
      this.inactiveUsers.on("reset", this.accountReset);
      return currentUser.on("change:id", this.idChanged);
    };

    AccountView.prototype.idChanged = function() {
      if (currentUser.isSuperUser()) {
        return this.manualActivation.show();
      } else {
        return this.manualActivation.hide();
      }
    };

    AccountView.prototype.resetPasswordViaEmail = function(e) {
      var error, success,
        _this = this;
      e.preventDefault();
      if (this.emailBox.isEmpty()) {
        alert("Enter an email address!");
        return;
      }
      success = function() {
        return alert("Password has been reset. Check your inbox for new messages.");
      };
      error = newErrorCallback("Cannot reset password!", function() {
        return _this.emailForm.fadeIn();
      });
      this.emailForm.fadeOut();
      return utils.User.resetViaEmail(this.emailBox.val(), success, error);
    };

    AccountView.prototype.resetPasswordViaUsername = function(e) {
      var error, success,
        _this = this;
      e.preventDefault();
      if (this.usernameBox.isEmpty()) {
        alert("Enter an username!");
        return;
      }
      success = function() {
        return alert("Password has been reset. Check your inbox for new messages.");
      };
      error = newErrorCallback("Cannot reset password!", function() {
        return _this.usernameForm.fadeIn();
      });
      this.usernameForm.fadeOut();
      return utils.User.resetViaUsername(this.usernameBox.val(), success, error);
    };

    AccountView.prototype.refreshAccountList = function() {
      this.accountList.empty();
      return this.inactiveUsers.fetch();
    };

    AccountView.prototype.accountAdded = function(account) {
      var email, id, item,
        _this = this;
      email = account.get("email");
      id = account.get("id");
      item = $("<li>" + email + " : <a href='#/accounts/" + id + "'>Activate</a></li>");
      item.find("a").click(function() {
        var error, success;
        success = function() {
          alert("User " + email + " activated!");
          return item.remove();
        };
        error = newErrorCallback("Cannot activated that user!");
        return utils.User.activate(id, success, error);
      });
      return this.accountList.append(item);
    };

    AccountView.prototype.accountReset = function() {
      var i, _i, _ref, _results;
      if (this.inactiveUsers.length === 0) {
        this.accountList.append($("<li>No account to display</li>"));
        return;
      }
      _results = [];
      for (i = _i = 0, _ref = this.inactiveUsers.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
        _results.push(this.accountAdded(this.inactiveUsers.at(i)));
      }
      return _results;
    };

    return AccountView;

  })(Backbone.View);

  MainRouter = (function(_super) {

    __extends(MainRouter, _super);

    function MainRouter() {
      return MainRouter.__super__.constructor.apply(this, arguments);
    }

    MainRouter.prototype.routes = {
      "users/:id": "showUserInfo",
      "users/:id/information": "showUserInfo",
      "users/:id/skills": "listUserSkills",
      "users/:id/feedbacks": "listUserFeedbacks",
      "self": "showMyProfile",
      "self/skills": "listMySkills",
      "self/feedbacks": "listMyFeedbacks",
      "self/messages": "listMyMessages",
      "self/requests": "listMyRequests",
      "help": "search",
      "users": "listAllUsers",
      "users/:id/sendMessage": "sendMessageToUser",
      "users/:id/friends": "showFriends",
      "self/friends": "showMyFriends",
      "skills/proposals": "showProposals",
      "accountHelp": "account",
      "home": "goHome"
    };

    return MainRouter;

  })(Backbone.Router);

  $(function() {
    var mainRouter,
      _this = this;
    window.homePanel = $("#homePanel");
    window.profilePanel = $("#profilePanel");
    window.searchPanel = $("#searchPanel");
    window.messagePanel = $("#messagePanel");
    window.requestPanel = $("#requestPanel");
    window.resultPanel = $("#resultPanel");
    window.proposalsPanel = $("#proposalsPanel");
    window.accountPanel = $("#accountPanel");
    window.panels = $(".body > div");
    window.showPanel = function(panel) {
      if (panel.is(":visible")) {
        return;
      }
      return window.panels.visibles().fadeReplace(panel);
    };
    window.skillDatabase = new model.SkillDatabase();
    window.skillDatabase.fetch();
    window.registrationView = new RegistrationForm({
      el: $("#registrationForm")
    });
    window.loginView = new LoginForm({
      el: $("#loginForm")
    });
    window.personalMessageView = new MessageCollectionView({
      el: $("#messagePanel ul"),
      model: window.currentUser.messages
    });
    window.profile = new Profile({
      el: $("#profilePanel")
    });
    window.searchView = new SearchView({
      el: $("#searchPanel")
    });
    window.requestView = new FriendshipRequestCollectionView({
      el: $("#requestPanel ul"),
      model: window.currentUser.requests
    });
    window.userView = new UserCollectionView({
      el: $("#resultPanel ul")
    });
    window.proposalsView = new ProposalsView({
      el: proposalsPanel
    });
    window.accountView = new AccountView({
      el: accountPanel
    });
    mainRouter = new MainRouter();
    mainRouter.on("route:listUserSkills", function(id) {
      window.showPanel(profilePanel);
      profile.showSection("skills");
      if (targetUser.get("id") !== id) {
        profile.model.set("id", id);
        return profile.model.fetch({
          success: function() {
            return profile.skillSection.refresh();
          }
        });
      } else {
        return profile.skillSection.refresh();
      }
    });
    mainRouter.on("route:showUserInfo", function(id) {
      window.showPanel(profilePanel);
      profile.showSection("information");
      if (targetUser.get("id") !== id) {
        profile.model.set("id", id);
        return profile.model.fetch();
      }
    });
    mainRouter.on("route:listUserFeedbacks", function(id) {
      window.showPanel(profilePanel);
      profile.showSection("feedbacks");
      if (targetUser.get("id") !== id) {
        profile.model.set("id", id);
        return profile.model.fetch({
          success: function() {
            return profile.feedbackSection.refresh();
          }
        });
      } else {
        return profile.feedbackSection.refresh();
      }
    });
    mainRouter.on("route:listMyFeedbacks", function() {
      window.showPanel(profilePanel);
      profile.showSection("feedbacks");
      profile.model.copyFrom(window.currentUser);
      return profile.model.fetch({
        success: function() {
          return profile.feedbackSection.refresh();
        }
      });
    });
    mainRouter.on("route:sendMessageToUser", function() {
      window.showPanel(profilePanel);
      return profile.showSection("sendMessage");
    });
    mainRouter.on("route:listMyMessages", function() {
      window.showPanel(messagePanel);
      personalMessageView.model.reset();
      return personalMessageView.model.fetch();
    });
    mainRouter.on("route:listMyRequests", function() {
      window.showPanel(requestPanel);
      requestView.model.reset();
      return requestView.model.fetch();
    });
    mainRouter.on("route:search", function() {
      window.showPanel(searchPanel);
      searchView.searchBox.val("");
      return searchView.show();
    });
    mainRouter.on("route:listAllUsers", function() {
      window.showPanel(resultPanel);
      userView.model.url = function() {
        return window.ROOT_URL + "/users";
      };
      userView.model.reset();
      return userView.model.fetch();
    });
    mainRouter.on("route:showMyProfile", function() {
      window.showPanel(profilePanel);
      profile.showSection("information");
      return window.loadPersonalInfo();
    });
    $(".barContent a[href='#/logout']").click(function(e) {
      e.preventDefault();
      $.cookie(window.COOKIE_NAME, null);
      return loginView.hideLoggedGui();
    });
    mainRouter.on("route:showFriends", function(id) {
      window.showPanel(resultPanel);
      userView.model.url = function() {
        return "" + ROOT_URL + "/users/" + id + "/friends";
      };
      userView.model.reset();
      return userView.model.fetch();
    });
    mainRouter.on("route:showMyFriends", function() {
      window.showPanel(resultPanel);
      userView.model.url = function() {
        return ("" + ROOT_URL + "/users/") + currentUser.get("id") + "/friends";
      };
      userView.model.reset();
      return userView.model.fetch();
    });
    mainRouter.on("route:showProposals", function() {
      window.showPanel(proposalsPanel);
      return proposalsView.refresh();
    });
    mainRouter.on("route:account", function() {
      window.showPanel(accountPanel);
      return accountView.refreshAccountList();
    });
    mainRouter.on("route:goHome", function() {
      return window.showPanel(homePanel);
    });
    $(window).resize(function() {
      var labels;
      labels = $(".right .quickIcon label");
      if ($(".body").width() < 866) {
        return labels.hide();
      } else {
        return labels.show();
      }
    });
    if (isLogged()) {
      loginView.showLoggedGui();
      if (!currentUser.get("id")) {
        window.loadPersonalInfo();
      }
    }
    return Backbone.history.start();
  });

}).call(this);
